package com.seed.core.builder.datapermis;

import com.seed.core.builder.pojo.Join1;
import com.seed.core.builder.pojo.WhereCondition1;
import com.seed.core.builder.query.InBuilder;
import com.seed.core.builder.search.SearchedWrapper;
import com.seed.core.pojo.seed.Seed;
import com.seed.core.query.pojo.Searched;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class DataPermisWrapper {

    private final List<List<WhereCondition1>> wheres = new ArrayList<>();
    private final Map<String, Join1> joins = new LinkedHashMap<>(); // 表关联对象
    private final Map<String, InBuilder> inBuilders = new LinkedHashMap<>();
    private final List<Map<String, Searched>> fillDataPermied = new ArrayList<>(); // fill对象使用

    public DataPermisWrapper(Seed selfSeed, List<Map<String, Searched>> dataPermieds) {
        for (Map<String, Searched> searcheds: dataPermieds) {
            SearchedWrapper wrapper = new SearchedWrapper(selfSeed, searcheds);
            joins.putAll(wrapper.getJoins());
            inBuilders.putAll(wrapper.getInBuilders());
            fillDataPermied.add(wrapper.getFillSearcheds());

            List<WhereCondition1> conditions = new ArrayList<>();
            if(!wrapper.getWheres().isEmpty()) {
                conditions.add(wrapper.getWheres().get(0));
            } else if(!wrapper.getInBuilders().isEmpty()) {
//                conditions.add(wrapper.getInQuerys().get(0).getQueryCondition());
            } else {
//                conditions.add(QueryCondition.createEmpty());
            }
            wheres.add(conditions);
        }
    }

    public List<List<WhereCondition1>> getWheres() {
        return wheres;
    }

    public Map<String, Join1> getJoins() {
        return joins;
    }

    public Map<String, InBuilder> getInBuilders() {
        return inBuilders;
    }

    public List<Map<String, Searched>> getFillDataPermied() {
        return fillDataPermied;
    }
}
